#include "mq_send_receive.h"
#include <unistd.h>



int main(int argc, char const *argv[])
{   
    char *name="/my_queue";
    char buf[100];  
    mqd_t mqd=create_message_queue(name);
    while (1)
    {   
        memset(buf,0,sizeof(buf));
        int count=read(STDIN_FILENO, buf, sizeof(buf));

        if (count== 0)
        {
            //结束，最后发送一个退出消息
            send_buf(mqd, "exit",5);
            break;
        }
        else if (count < 0){

            perror("read");
            exit(1);
        }

        if((send_buf(mqd, buf,10))== -1){

            perror("send");
            exit(1);
        }else
        {
            printf("send success\n");
        }

    }
    
    close(mqd);
    printf("produce end\n");
    

    return 0;
}
